<!--
 * @Author: 莫宗蓝
 * @Date: 2021-05-31 16:48:52
 * @LastEditTime: 2022-12-30 14:18:51
 * @LastEditors: 莫宗蓝 mozl@augurit.com
 * @Description: 鹰眼视图 查看当前浏览的大致位置
-->
<template>
  <div id="minMap">
    <i @click="closeMinMap" id="minMap-icon-close"></i>
  </div>
</template>
<script>
let minViewer;
import EagleEyeMap from "./js/EagleEyeMap";
import MinMapLayerTree from "./js/MinMapLayerTree"
import serverData4Config from "@/views/js/net/serverData4Config";

let viewer = undefined;
let minMap = undefined;
let minMapLayerTree = undefined;
export default {
  components: {},
  props: {},
  data() {
    return {
      layerTree:undefined,
      baseLayers:undefined,
    };
  },
  created() {},
  mounted() {
    viewer = CIM.viewer;
    minMapLayerTree = new MinMapLayerTree();
    this.initMinMap();
    this.getLayerTreeData();    
  },
  destroyed() {
    minMapLayerTree.destroy();
    minMap.removeInputAction(minViewer);
    minMap.destroy();
  },
  computed: {},
  watch: {
    layerTree(newV){
      if(newV){
        minMapLayerTree.initData(minViewer,newV);
        this.getWidgetConfig();
      }
    },
    baseLayers(newV){
      if(newV){
        let layerTreeDom = minMapLayerTree._minMapLayerTree.layerTreeDom;
        if(newV.length>0){
            let _aglayerIds  = minMapLayerTree._minMapLayerTree._aglayerIds;
            layerTreeDom.setLayerCheck(_aglayerIds[0],false);
        }
        newV.forEach(element => {
          if(element.layerid){
            layerTreeDom.setLayerCheck(element.layerid,true);
          }else if(newV.length===1 && element.layerid===""){
            let _aglayerIds  = minMapLayerTree._minMapLayerTree._aglayerIds;
            layerTreeDom.setLayerCheck(_aglayerIds[0],true);
        }
        });
      }
    }
  },
  methods: {
    getWidgetConfig(){
      agcim.widgets.widgetExtendField
        .getWidgetInfoByCode("agcim-EagleEyeMap")
        .then((res) => {
          if(res.content.widgetLevelsData!=="") this.baseLayers = JSON.parse(res.content.widgetLevelsData);
        });
    },

    initLayerTree(){
      
    },
    initMinMap(){
      minMap = new EagleEyeMap(viewer);
      minMap.creatMap("minMap");
      minMap.mainMapExtentChange();
      minViewer =  minMap.minViewer;
    },
    closeMinMap() {
      minMap.destroy();
      this.$emit("close", { code: "EagleEyeMap" });
    },
    //获取图层树数据
    getLayerTreeData() {
        let projectName = CIM_LAYERTREE_NAME;
        let p = {
            projectName: projectName,
            emptydir: true,
        };
        serverData4Config.getLayerTreeData(p).then(data=>{
          this.layerTree = data;
        });
    }
  },
};
</script>
<style scoped lang="scss">
#minMap {
  width: 300px;
  height: 200px;
  position: absolute;
  bottom: 35px;
  right: 130px;
  background: #fff;
  border: 1px solid #999;
  -webkit-box-shadow: 0px 0px 15px #999;
  box-shadow: 0px 0px 15px #999;
  z-index: 10;
}
#minMap .cesium-viewer-toolbar {
  display: none;
}
#minMap-icon-close {
  position: absolute;
  top: 10px;
  right: 10px;
  height: 24px;
  width: 24px;
  z-index: 10;
  background: url("./img/close.png");
}
#minMap-icon-close:hover {
  cursor: pointer;
  opacity: 0.8;
}
</style>
